package com.lagou.edu.test;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.KeyEvent;
import java.io.*;

public class SendQQandWEIXIN {
    public static void main(String[] args)throws AWTException {



        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable tText = null;
        Toolkit tolkit = Toolkit.getDefaultToolkit();
        File file=new File("C:\\Users\\董红广\\Desktop\\我的144行情书");
        String bestWord=fileTransferString(file);
//      String[] lists ={"我只爱你四天,春天夏天秋天冬天","我只爱你三天,昨天,今天,明天.","我只爱你两天,白天,黑天","我只爱你一天,每一天","爱你么么哒"};
        String[] lists=bestWord.split(",");
        Robot robot = new Robot();
        robot.delay(10000);//延迟十秒，主要是为了预留出打开窗口的时间，括号内的单位为毫秒
        for (int i = 0; i < lists.length; i++) {//循环五次，当然，如果爱得深，你死循环也没问题设置为100
            tText = new StringSelection(lists[i]); //自己定义就需要把这行注释，下行取消注释
//            tText = new StringSelection("爱你每一天");//如果爱得深，把这行取消注释，把内容更换掉你自己想说的
            clip.setContents(tText, null);
            robot.keyPress( KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            //robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.delay(3000);
            robot.keyPress( KeyEvent.VK_ENTER);
            robot.delay(10000);
        }
    }

    public static String fileTransferString(File file){
        StringBuilder stringBuilder=new StringBuilder();
        try {
            FileInputStream fileInputStream=new FileInputStream(file);
            InputStreamReader inputStreamReader=new InputStreamReader(fileInputStream,"UTF-8");
            BufferedReader bufferedReader=new BufferedReader(inputStreamReader);
            String content="";

            while(content!=null){
                content=bufferedReader.readLine();
                if(null==content){
                    break;
                }
                stringBuilder.append(content);
            }
            bufferedReader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return stringBuilder.toString();
    }
}